package com.llb666.e.shop.domain.service;

import com.llb666.e.shop.api.vo.MyOrdersVo;
import com.llb666.e.shop.api.vo.OrderStatusCountsVo;
import com.llb666.e.shop.domain.entity.OrderItems;
import com.llb666.e.shop.domain.entity.OrderStatus;
import com.llb666.e.shop.domain.entity.Orders;
import com.llb666.e.shop.domain.repository.OrderItemsRepository;
import com.llb666.e.shop.domain.repository.OrdersRepository;
import com.llb666.e.shop.infracore.web.PagedGridResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 斌~
 * @date 2022/9/12 下午6:13
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class MyOrdersService {
    
    private final OrdersRepository ordersRepository;
    private final OrderItemsRepository orderItemsRepository;

    public OrderStatusCountsVo getOrderStatusCounts(String userId) {
        return ordersRepository.getOrderStatusCounts(userId);
    }

    public void updateDeliverOrderStatus(String orderId) {
        ordersRepository.updateDeliverOrderStatus(orderId);
    }

    public PagedGridResult<MyOrdersVo> queryMyOrders(String userId, Integer orderStatus, Integer page, Integer pageSize) {
        return ordersRepository.queryMyOrderByStatus(userId,orderStatus,page,pageSize);
    }

    public boolean updateReceiveOrderStatus(String orderId) {
       return ordersRepository.updateReceiveOrderStatus(orderId);
    }

    public boolean deleteOrder(String userId, String orderId) {
       return ordersRepository.deleteOrder(userId,orderId);
    }

    public PagedGridResult<OrderStatus> getOrdersTrend(String userId, Integer page, Integer pageSize) {
        return  ordersRepository.getMyOrderTrend(userId,page,pageSize);
    }

    public Orders queryMyOrder(String userId, String orderId) {
        return ordersRepository.queryMyOrder(userId,orderId);
    }

    /**
     * 查询代办订单.
     * @param orderId 订单id
     * @return 订单列表
     */
    public List<OrderItems> queryPendingComment(String orderId) {
        return orderItemsRepository.queryPendingComment(orderId);
    }
}
